package com.bw.paper.mvp.view.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.bw.paper.App;
import com.bw.paper.R;
import com.bw.paper.db.UserEntityDao;
import com.bw.paper.entity.UserEntity;

public class UpActivity extends AppCompatActivity
        implements View.OnClickListener {

    private ImageView updateBgImg;
    private ImageView updateBack;
    private TextView updateEdit;
    private TextView updateHeadLv;
    private TextView exit;
    private ImageView updateIv;
    private TextView upName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_up);
        initView();
        try {
            UserEntity unique = App.getInstance().getDaoSession().queryBuilder(UserEntity.class).list().get(0);
            String user_name = unique.getUser_name();
            int user_integral = unique.getUser_integral();
            String user_img = unique.getUser_img();
            Glide.with(this).load(user_img).into(updateBgImg);
            Glide.with(this).load(user_img).into(updateIv);
            upName.setText(user_name);
            updateHeadLv.setText("LV." + user_integral);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private void initView() {
        updateBgImg = (ImageView) findViewById(R.id.update_bg_img);
        updateBack = (ImageView) findViewById(R.id.update_back);
        updateEdit = (TextView) findViewById(R.id.update_edit);
        updateHeadLv = (TextView) findViewById(R.id.update_head_lv);
        exit = (TextView) findViewById(R.id.exit);

        updateIv = (ImageView) findViewById(R.id.update_iv);
        upName = (TextView) findViewById(R.id.up_name);

        updateBack.setOnClickListener(this::onClick);
        updateEdit.setOnClickListener(this::onClick);
        exit.setOnClickListener(this::onClick);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.update_back) {
            Intent intent = new Intent(UpActivity.this, FragmActivity.class);
            startActivity(intent);
            finish();
        }
        if (id == R.id.update_edit) {
            Intent intent = new Intent(UpActivity.this, UpUserActivity.class);
            startActivity(intent);
            finish();
        }
        if (id == R.id.exit) {
            App.getInstance().getDaoSession().deleteAll(UserEntity.class);
            startActivity(new Intent(this,LoginActivity.class));
            finish();
        }


    }

}